const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property
    speed: number = 6;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    onAnimCompleted(){
       this.node.destroy();
       this.destroy();
       
    }

    onCollisionEnter (){
        let anim = this.getComponent(cc.Animation);
        anim.play('Explosion');
    }

    isOutbounded(): boolean{
        // Boundary Check
        let posY = this.node.getPositionY();
        let screenSize = cc.director.getWinSize();
        if(posY >= screenSize.height/2){
            return true;
        }
    }

    start () {

    }
    moveBy(duration: number, pos: cc.Vec2){
        this.node.runAction(cc.moveBy(duration, pos));
    }

    update(dt) {
        this.moveBy(dt, cc.p(0, -this.speed));
        if (this.isOutbounded()) {
            this.node.destroy();
            this.destroy();
        }
    }
}
